$(function () {
    $('#activity-register-form').on('submit', function (evt) {
        evt.preventDefault();
        var thiz = $(this);
        var payload = PS.form.serialize(thiz);
        PS.ajax.post('/inapi/activity', payload, 'json')
            .done(function (data) {
                if (data.code && data.code !== 0) {
                    $('#message-error').html(data.code + ' : ' + data.message).removeClass('hidden');
                    return;
                }
                console.log(data);
                window.location.href = '/activity/' + data.activityId + '/' + data._id
            })
            .fail(function (data, status) {
                $('#message-error').html(status + ' : ' + data).removeClass('hidden');
            });
    })
});
